package cn.tedu.thread;/**
 * @Author 金帮嘉诚 @Date 2021-06-22 星期二 17:09
 */
/*本类用于测试多线程编程方式2*/

/**
 * 知识点
 */
public class TestThread2 {
    public static void main(String[] args) {
        MyRunnable my1 = new MyRunnable();
//        MyRunnable my2 = new MyRunnable();
//        MyRunnable my3 = new MyRunnable();
//        MyRunnable my4 = new MyRunnable();

//        my1.run();
//        my2.run();
//        my3.run();
//        my4.run();

        //四个线程 各自完成一遍同一个任务
        Thread t1 = new Thread(my1,"杰克");//构造方法
        Thread t2 = new Thread(my1,"朱丽叶");
        Thread t3 = new Thread(my1,"白雪公主");
        Thread t4 = new Thread(my1,"啊啊啊啊啊");

        t1.start();
        t2.start();
        t3.start();
        t4.start();

    }
}

//
/*方式二：实现Runnable接口完成*/
class MyRunnable implements Runnable {

    //
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            //如何获取name
            //
            //currentThread()
            //
            System.out.println(i + "=" + Thread.currentThread().getName());
        }
    }
}